public class Main_2 {
    public static void main(String []args) {
        System.out.println("Hello World!");
        System.out.println(toHumpStr("a"));
        System.out.println(toHumpStr("a_"));
        System.out.println(toHumpStr("a_b"));
        System.out.println(toHumpStr("a_bc_d"));
        System.out.println(toSnakeStr("a"));
        System.out.println(toSnakeStr("aB"));
        System.out.println(toSnakeStr("aBc"));
        System.out.println(toSnakeStr("aBcD"));
    }
    private static final String S_ = "_";
    /** 蛇形转驼峰形 */
    public static String toHumpStr(String snakeStr) {
        if(null == snakeStr || !snakeStr.contains(S_)){ return snakeStr; }
        StringBuilder sb = new StringBuilder();
        char[] chars = snakeStr.toCharArray();
        boolean is = false;
        for (char c : chars) {
            if( '_' == c ){
                is = true;
            }else if( is ){
                sb.append(Character.toUpperCase(c));
                is = false;
            }else{
                sb.append(c);
            }
        }
        return sb.toString();
    }
    /** 驼峰形转蛇形 */
    public static String toSnakeStr(String humpStr) {
        if( null == humpStr || humpStr.length() <= 1 ){ return humpStr; }
        StringBuilder sb = new StringBuilder(humpStr.length());
        char[] chars = humpStr.toCharArray();
        for (char c : chars) {
            if(Character.isUpperCase(c)){ sb.append(S_); }
            sb.append(c);
        }
        return sb.toString().toLowerCase();
    }
}

